package com.ruoyi.web.controller.marketing;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.marketing.domain.AwardDetail;
import com.ruoyi.marketing.domain.AwardPerson;
import com.ruoyi.marketing.service.IAwardDetailService;
import com.ruoyi.marketing.service.IAwardPersonService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.marketing.domain.AwardPage;
import com.ruoyi.marketing.service.IAwardPageService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营销活动列表Controller
 *
 * @author hao
 * @date 2023-01-31
 */
@RestController
@RequestMapping("/marketing/awardpage")
public class AwardPageController extends BaseController {
    @Autowired // 明细页面
    private IAwardPageService awardPageService;

    @Autowired // 查看明细 - 活动人数
    private IAwardPersonService awardPersonService;

    @Autowired // 查看明细 - 活动奖励
    private IAwardDetailService awardDetailService;

    /**
     * 查询营销活动列表列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:awardpage:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardPage awardPage) {
        startPage();
        List<AwardPage> list = awardPageService.selectAwardPageList(awardPage);
        return getDataTable(list);
    }

    /**
     * 获取营销活动列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('marketing:awardpage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardPageService.getById(id));
    }

    /**
     * 新增营销活动列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:awardpage:add')")
    @Log(title = "营销活动列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardPage awardPage) {
        return toAjax(awardPageService.save(awardPage));
    }

    /**
     * 修改营销活动列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:awardpage:edit')")
    @Log(title = "营销活动列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardPage awardPage) {
        return toAjax(awardPageService.updateById(awardPage));
    }

    /**
     * 删除营销活动列表
     */
    @PreAuthorize("@ss.hasPermi('marketing:awardpage:remove')")
    @Log(title = "营销活动列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardPageService.removeBatchByIds(Arrays.asList(ids)));
    }

    /**
     * 查看详情-查看参加活动人数
     */
    @GetMapping("/person/list")
    public TableDataInfo personList() {
        List<AwardPerson> list = awardPersonService.selectAwardPersonList();
        return getDataTable(list);
    }

    /**
     * 查看详情-查看活动奖励
     */
    @GetMapping("/award/list")
    public TableDataInfo awardList() {
        List<AwardDetail> list = awardDetailService.selectAwardDetailList();
        return getDataTable(list);
    }
}
